import { createRouter, createWebHashHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';

import Layout from '../layout/index.vue';

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Home',
        component: () => import('@views/home/index.vue')
      },
      {
        path: 'template/:templateId',
        name: 'TemplateDetail',
        component: () => import('@views/template-editor/detail.vue')
      }
    ]
  },
  {
    path: '/template-editor',
    name: 'TemplateEditor',
    component: () => import('@views/template-editor/editor.vue')
  },
  {
    /* 页面不存在，跳转至 404 */
    path: '/:pathMatch(.*)*',
    redirect: {
      name: 'NotFound'
    }
  },
  {
    /* 404 */
    path: '/not-found',
    name: 'NotFound',
    component: () => import('../layout/NotFound.vue')
  }
];

export default createRouter({
  history: createWebHashHistory('/link/editor/#/'),
  routes
});
